home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / srefv112.zip / PREFILTR.80 < prev    next >
Text File  |  1996-05-04  |  4KB  |  114 lines

  1. /*A pre filter for SRE-FILTER.
  2.  
  3. This pre-filter implements support for the GOREMOTE server
  4. remote control package of GoServe.
  5.  
  6. If PRE_FILTER=YES, then only SUPERUSERs will be allowed acces to
  7. GoRemore.  If PRE_FILTER=FIRST, then everyone is given access.
  8.  
  9. In this version, PREFILTR will check to see if the request is for
  10. GORMxxx or GOREMOTE.HTM, or GOREMOTE/GORMxxx and GOREMOTE/GOREMOTE.HTM.
  11. Thus, GOREMOTE must be installed either in the root of the data directory,
  12. or in the GOREMOTE/ subdirectory of the data directory.
  13.  
  14. PREFILTR should return: status , message:
  15. status=0:  SRE-FILTER should continue
  16. status=1:  some form of completion, SRE-FILTER should end (perhaps after
  17. recording request info)
  18.  
  19. The message will be saved as the PREFILTER_RESULT variable 
  20.  
  21.  
  22. */
  23.  
  24. prefiltr:
  25.  
  26. parse arg source,request,sel,privs
  27.  
  28.  
  29. issent=completed()
  30. if issent=1 then  /* if cached request, nothing here to do.. */
  31.   return '1 , ok cached'
  32.  
  33. tsel=translate(sel)
  34. if abbrev(tsel,'GOR')=0 & abbrev(tsel,'GOS')=0 then return '0 , ok'   /* quick check */
  35.  
  36. /* see it this is GOREMOTE.HTM or GORM*.HTM, in either main or
  37. GOREMOTE directory */
  38.  
  39. foo=translate(sel,' ','/\')
  40. endword=word(foo,words(foo))
  41.  
  42. sel1=strip(tsel,,'/')
  43.  
  44. hi1=abbrev(sel1,"GOREMOTE")
  45. hi2=abbrev(sel1,"GORM")
  46. hi3=abbrev(sel1,"GOREMOTE/GORM")
  47. hi4=abbrev(sel1,"GOREMOTE/GOREMOTE")
  48. if hi1+hi2+hi3+hi4=0 then
  49.         return '0 , ok'
  50.  
  51.  
  52. /* if here, it's a goremote command -- srefilter will not have to
  53. do anything with this request (except record it). */
  54.  
  55. verb=word(request,1)
  56. /* check privs? */
  57. if privs<>" " then do
  58.   tp=translate(privs)
  59.   IF verb="GET" then do
  60.     if (wordpos("SUPERUSER",tp)+wordpos("INHOUSE",tp))=0   then do
  61.         foo=response('unauth', 'you do not have sufficient privileges for '||endword)
  62.         return '1, not allowed ' /* let srefilter record this .. */
  63.     END
  64.   end
  65.   if verb="POST" then do
  66.     if wordpos("SUPERUSER",tp)=0   then DO
  67.         foo=response('unauth', 'you do not have sufficient privileges for '||endword)
  68.         return '1, not allowed ' /* let srefilter record this .. */
  69.     END
  70.   end
  71. end
  72.  
  73. sel=sref_replacestrg(sel,'GOREMOTE.HTM','GOREMOTE')  /* a common error .. */
  74.  
  75. /* if here, goremote and sufficient privs -- do it ! */
  76. if verb="GET" then do
  77.   say " GoRemote= " verb sel
  78.   foo=goremote(verb,sel)
  79.  
  80. end
  81. else do
  82.     say " GOREMOTE= " verb endword
  83.    foo=goremote(verb,endword)
  84. end
  85. return ' 1 , did goremote '
  86.  
  87. response: procedure
  88.   parse arg request, message
  89.  
  90.   select
  91.     when request='badreq'   then use='400 Bad Request Syntax'
  92.     when request='notfound' then use='404 Not found'
  93.     when request='forbid'   then use='403 Forbidden'
  94.     when request='unauth'   then use='401 Unauthorized'
  95.     otherwise
  96.     end  /* Add others to this list as needed */
  97.   /* Now set the response and build the response file */
  98.   'RESPONSE HTTP/1.0' use    /* Set HTTP response line */
  99.   parse var use code text
  100.   crlf='0d0a'x; out=''
  101.   out=out||'<!doctype html public "-//IETF//DTD HTML 2.0//EN">'crlf
  102.   out=out||"<html><head><title>"text"</title></head>"crlf
  103.   out=out||"<body><h2>Sorry...</h2>"crlf
  104.   out=out||"<p>The request from your Web client" message"."crlf
  105.   out=out||"<hr><em>HTTP response code:</em>" code '['text']'crlf
  106.   out=out||"<br><em>From server at:</em>" servername()crlf
  107.   out=out||"<br><em>Running:</em>" server()crlf
  108.   out=out||"</body></html>"crlf
  109.   'VAR TYPE text/html AS Response NAME out'  /* send it */
  110.   return ''                                  /* [called as function] */
  111.  
  112.  
  113.  
  114.